library(tidyverse)
p.values <- c(
  0.843,
  0.821,
  0.001,
  0.102,
  0.152
)
names(p.values) <- c(
  "Municipal", 
  "State",
  "Ministerial",
  "Federal",
  "Army"
)
p.values <- sort(p.values)
ben_hochberg <- (1:5)/5 * .05
p.values[p.values < ben_hochberg]
inst_p <- p.values

# BRUTE FORCE -------------------------------------------------------------

p.values <- c(
  0.433,
  0.120,
  0,
  0.098,
  0.666
)
names(p.values) <- c(
  "Municipal", 
  "State",
  "Ministerial",
  "Federal",
  "Army"
)
p.values <- sort(p.values)
p.values[p.values < ben_hochberg]
brf_p <- p.values

# THREATS -----------------------------------------------------------------

p.values <- c(
  0.100,
  0.335,
  0,
  0.245,
  0.616
)
names(p.values) <- c(
  "Municipal", 
  "State",
  "Ministerial",
  "Federal",
  "Army"
)
p.values <- sort(p.values)
p.values[p.values < ben_hochberg]

ben_hoch_df <- data.frame(
  inst = inst_p,
  brf = brf_p,
  threat = p.values,
  cutoff = ben_hochberg,
  index = 1:5
)

ggplot(
  ben_hoch_df,
  aes(
    x = index,
    y = inst,
    label = names(inst_p)
  )
) + geom_point(aes(colour = inst < cutoff)) + theme_bw() + 
  geom_line(aes(y = cutoff)) + 
  geom_text(aes(x = index + .1, y = inst - .015)) + 
  scale_color_manual(values = c("black", "red"), labels = c("",""), guide = FALSE) + 
  labs(
    title = "Coefficients: institutionalized torture",
    y = "P-value on interaction between authority and reform",
    x = "p-value rank"
  ) 

ggplot(
  ben_hoch_df,
  aes(
    x = index,
    y = brf,
    label = names(inst_p)
  )
) + geom_point(aes(colour = brf < cutoff)) + theme_bw() + 
  geom_line(aes(y = cutoff)) + 
  geom_text(aes(x = index + .1, y = brf - .015)) + 
  scale_color_manual(values = c("black", "red"), labels = c("",""), guide = FALSE) + 
  labs(
    title = "Coefficients: brute force",
    y = "P-value on interaction between authority and reform",
    x = "p-value rank"
  ) 

ggplot(
  ben_hoch_df,
  aes(
    x = index,
    y = threat,
    label = names(p.values)
  )
) + geom_point(aes(colour = threat < cutoff)) + theme_bw() + 
  geom_line(aes(y = cutoff)) + 
  geom_text(aes(x = index + .1, y = threat - .015)) + 
  scale_color_manual(values = c("black", "red"), labels = c("",""), guide = FALSE) + 
  labs(
    title = "Coefficients: threats",
    y = "P-value on interaction between authority and reform",
    x = "p-value rank"
  ) 

####MARGINS: JOINT OPERATIONS
p.values <- c(0.022, 0.067, 0.010, 0.001, 0.093)
names(p.values) <- c(
  "Municipal", 
  "State",
  "Ministerial",
  "Federal",
  "Army"
)

inst_p <- sort(p.values)
inst_p[inst_p < ben_hochberg]


p.values <- c(0.028, 0.654, 0.091, 0.001, 0.082)
names(p.values) <- c(
  "Municipal", 
  "State",
  "Ministerial",
  "Federal",
  "Army"
)

brf_p <- sort(p.values)
brf_p[brf_p < ben_hochberg]


p.values <- c(0.128, 0.575, 0.040, 0.002, 0.635)
names(p.values) <- c(
  "Municipal", 
  "State",
  "Ministerial",
  "Federal",
  "Army"
)

threat_p <- sort(p.values)
threat_p[threat_p < ben_hochberg]


ben_hoch_df <- data.frame(
  inst = inst_p,
  brf = brf_p,
  threat = threat_p,
  cutoff = ben_hochberg,
  index = 1:5
)

ggplot(
  ben_hoch_df,
  aes(
    x = index,
    y = inst,
    label = names(inst_p)
  )
) + geom_point(aes(colour = inst < cutoff)) + theme_bw() + 
  geom_line(aes(y = cutoff)) + 
  geom_text(aes(x = index + .1, y = inst - .0015)) + 
  scale_color_manual(values = c("black", "red"), labels = c("",""), guide = FALSE) + 
  labs(
    title = "Institutionalized torture",
    y = "P-value for within-authority marginal effect: joint operation",
    x = "p-value rank"
  ) 

ggplot(
  ben_hoch_df,
  aes(
    x = index,
    y = brf,
    label = names(brf_p)
  )
) + geom_point(aes(colour = brf < cutoff)) + theme_bw() + 
  geom_line(aes(y = cutoff)) + 
  geom_text(aes(x = index + .1, y = brf - .015)) + 
  scale_color_manual(values = c("black", "red"), labels = c("",""), guide = FALSE) + 
  labs(
    title = "Brute force",
    y = "P-value for within-authority marginal effect: joint operation",
    x = "p-value rank"
  ) 

ggplot(
  ben_hoch_df,
  aes(
    x = index,
    y = threat,
    label = names(threat_p)
  )
) + geom_point(aes(colour = threat < cutoff)) + theme_bw() + 
  geom_line(aes(y = cutoff)) + 
  geom_text(aes(x = index + .1, y = threat - .015)) + 
  scale_color_manual(values = c("black", "red"), labels = c("",""), guide = FALSE) + 
  labs(
    title = "Threats",
    y = "P-value for within-authority marginal effect: joint operation",
    x = "p-value rank"
  ) 


# MARGINS: Reform ---------------------------------------------------------

p.values <- c(0.843,0.967,0,0.119,0.170)
names(p.values) <- c(
  "Municipal", 
  "State",
  "Ministerial",
  "Federal",
  "Army"
)

inst_p <- sort(p.values)
inst_p[inst_p < ben_hochberg]


p.values <- c(0.433,0.286,0,0.32,0.948)
names(p.values) <- c(
  "Municipal", 
  "State",
  "Ministerial",
  "Federal",
  "Army"
)

brf_p <- sort(p.values)
brf_p[brf_p < ben_hochberg]


p.values <- c(0.1,0.971,0,0.077,0.954)
names(p.values) <- c(
  "Municipal", 
  "State",
  "Ministerial",
  "Federal",
  "Army"
)

threat_p <- sort(p.values)
threat_p[threat_p < ben_hochberg]


ben_hoch_df <- data.frame(
  inst = inst_p,
  brf = brf_p,
  threat = threat_p,
  cutoff = ben_hochberg,
  index = 1:5
)

ggplot(
  ben_hoch_df,
  aes(
    x = index,
    y = inst,
    label = names(inst_p)
  )
) + geom_point(aes(colour = inst < cutoff)) + theme_bw() + 
  geom_line(aes(y = cutoff)) + 
  geom_text(aes(x = index + .1, y = inst - .015)) + 
  scale_color_manual(values = c("black", "red"), labels = c("",""), guide = FALSE) + 
  labs(
    title = "Institutionalized torture",
    y = "P-value for within-authority marginal effect: reform",
    x = "p-value rank"
  ) 

ggplot(
  ben_hoch_df,
  aes(
    x = index,
    y = brf,
    label = names(brf_p)
  )
) + geom_point(aes(colour = brf < cutoff)) + theme_bw() + 
  geom_line(aes(y = cutoff)) + 
  geom_text(aes(x = index + .1, y = brf - .015)) + 
  scale_color_manual(values = c("black", "red"), labels = c("",""), guide = FALSE) + 
  labs(
    title = "Brute force",
    y = "P-value for within-authority marginal effect: reform",
    x = "p-value rank"
  ) 

ggplot(
  ben_hoch_df,
  aes(
    x = index,
    y = threat,
    label = names(threat_p)
  )
) + geom_point(aes(colour = threat < cutoff)) + theme_bw() + 
  geom_line(aes(y = cutoff)) + 
  geom_text(aes(x = index + .1, y = threat - .015)) + 
  scale_color_manual(values = c("black", "red"), labels = c("",""), guide = FALSE) + 
  labs(
    title = "Threats",
    y = "P-value for within-authority marginal effect: reform",
    x = "p-value rank"
  ) 



